home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / fastwr50.zip / FWDEMO.PAS < prev   
Pascal/Delphi Source File  |  1987-11-09  |  7KB  |  168 lines

  1. (*
  2.                             FASTWR 4.0
  3.  
  4.  The FASTWR unit contains five fast, snow-and-flicker-free routines for
  5.  writing directly to (or reading from) the video memory of IBM PC/XT/AT's
  6.  and close compatibles. This new version takes advantage of several new
  7.  features in Turbo Pascal 4.0, notably the new unit capability and the
  8.  ability to link in standard .OBJ files. For an example of how to use
  9.  the routines in FASTWR.TPU, see the demonstration program that follows.
  10.  
  11.  Routines:
  12.  ---------
  13.  FastWrite : The old standby. Writes strings anywhere on the screen, in any
  14.    screen attribute, as rapidly as possible.
  15.  FastWriteNA : A version of FastWrite that uses the existing screen
  16.    attributes, so that you don't have to specify one. NA stands for No
  17.    Attribute.
  18.  ChangeAttribute : Changes the video attribute in the specified region of
  19.    the screen, leaving the characters untouched. I use this in moving bar
  20.    menus, myself.
  21.  MoveToScreen, MoveFromScreen : These are slightly optimized versions of
  22.    Bela Lubkin's routines of the same name. They differ in several minor
  23.    respects, most notably (a) the Length parameter asks for the number of
  24.    WORDS to move rather than BYTES and (b) they are a bit faster with snow
  25.    prevention off.
  26.  CurrentDisplay : This routine is new to FASTWR 4.0. It returns a scalar
  27.    value indicating whether the current display is a mono card (or Herc),
  28.    a CGA (or compatible), an EGA, MCGA, or VGA. This routine is used by
  29.    ReinitFastWrite when setting WaitForRetrace.
  30.  ReinitFastWrite : This routine is also new. It provides an easy means of
  31.    reinitializing the global variables BaseOfScreen and WaitForRetrace.
  32.    It is called automatically before your program gains control, so it is
  33.    normally needed only in memory resident programs.
  34.  
  35.  Global variables:
  36.  -----------------
  37.  WaitForRetrace : Comparable to the CheckSnow flag in the standard CRT unit.
  38.    MUST be false if writing to a monochrome display.
  39.  BaseOfScreen : Always either $B000 or $B800, unless you change it. Note
  40.    that ReinitFastWrite, like the CRT unit, assumes the current display page
  41.    is 0.
  42.  
  43.  Missing routines:
  44.  -----------------
  45.  A couple of routines found in earlier versions of FASTWR are now gone.
  46.  EgaInstalled has been replaced by the more informative CurrentDisplay
  47.  function. GetVideoMode's main function was to initialize WaitForRetrace
  48.  and BaseOfScreen; it has been replaced by ReinitFastWrite. FastWriteV is no
  49.  longer necessary, due to changes in the way that the compiler passes string
  50.  arguments. Plain FastWrite is now just as fast as FastWriteV was.
  51.  
  52.  Notes:
  53.  ------
  54.  Two penalties are imposed by the use of external assembly language
  55.  routines, as opposed to inline. (1) The order of the parameters passed to
  56.  external routines cannot be changed easily. If you want to change them,
  57.  you'll need MASM (or a compatible assembler). (2) The compiler's "smart
  58.  linking" feature does not work on external routines, since it has no sure
  59.  way of knowing where they end. Although FASTWR.TPU contains less than 600
  60.  bytes of code, you may want to eliminate one or more routines if you're
  61.  certain you'll never use them (FastWriteNA for example). (Again, to do this
  62.  you'll need MASM.) I've used externals for two reasons, by the way: (1) it
  63.  makes it easier for multiple routines to share code (see the CalcOffset
  64.  routine in FASTWR.ASM); (2) string parameters, when passed by value, can be
  65.  accessed as rapidly as VAR parameters, since the compiler cannot generate a
  66.  local copy of the string (saves code and stack space as well as time).
  67.  
  68.  FASTWR does not support multiple display pages, nor does it work in
  69.  anything other than 80-column text modes. If you need screen writing
  70.  routines that have these capabilities (or even if you don't), you might be
  71.  interested in Turbo Professional 4.0, a powerful library of over 400
  72.  routines designed especially for Turbo Pascal 4.0. Among other things,
  73.  Turbo Professional contains a plug-in replacement for the standard CRT unit
  74.  that incorporates all of the features found in FASTWR and more. For more
  75.  information, contact TurboPower Software at the number shown below.
  76.  
  77.  Thanks to Marshall Brain, whose own FASTWR.PAS was the basis for mine, and
  78.  to Bela Lubkin and Kim Kokkonen, who helped.
  79.  
  80.  
  81.  Copyright (c) 1986,1987 by Brian Foley
  82.  These routines may be freely used and distributed, for both private and
  83.  commercial use, so long as the routines themselves are not sold for profit.
  84.  
  85.  Brian Foley, CompuServe [76317,3247]
  86.  TurboPower Software
  87.  408-438-8608
  88.  9-5 (PST) Monday-Friday
  89. *)
  90.  
  91. program FastWriteDemo;
  92.   {-FastWrite demonstration}
  93.  
  94. uses
  95.   Crt,
  96.   FastWr;
  97.  
  98. var
  99.   Fore, Back,
  100.   I, Attr : Byte;
  101.   ScreenBuffer : array[1..2000] of Word;
  102.   N : Word;
  103.   C : Char;
  104. const
  105.   Bullet : String = '* FASTER THAN A SPEEDING BULLET! *';
  106.  
  107.   function  Attribute(Foreground, Background : Byte) : Byte;
  108.     {-Translates foreground and background colors into video attributes.
  109.      "and $7F" masks out the blink bit. Add $80 to the result to set it.}
  110.   begin
  111.     Attribute := ((Background shl 4) + Foreground) and $7F;
  112.   end;
  113.  
  114. begin
  115.   if WaitForRetrace then begin
  116.     Write('Does your screen generate snow? ');
  117.     C := ReadKey;
  118.     WaitForRetrace := (Upcase(C) = 'Y');
  119.   end;
  120.  
  121.   if Lo(LastMode) = 3 then begin
  122.     Fore := White;            {make these whatever you want}
  123.     Back := Magenta;
  124.   end
  125.   else begin
  126.     Fore := White;
  127.     Back := Black;
  128.   end;
  129.   Attr := Attribute(Fore, Back);
  130.   TextColor(Fore);
  131.   TextBackground(Back);
  132.   ClrScr;
  133.  
  134.   FastWrite('FastWriting is still even...', 6, 26, Attr);
  135.   Delay(1000);
  136.   FastWrite('**********************************', 9, 23, Attr);
  137.   for I := 10 to 20 do
  138.     FastWrite(Bullet, I, 23, Attr);
  139.   FastWrite('**********************************', 21, 23, Attr);
  140.  
  141.   {now save the entire screen}
  142.   MoveFromScreen(Mem[BaseOfScreen:0], ScreenBuffer, 2000);
  143.  
  144.   {now let's play with the saved screen, setting blink bits}
  145.   for N := 1 to 2000 do
  146.     ScreenBuffer[N] := ScreenBuffer[N] xor $8000;
  147.   Delay(1000);
  148.   FastWrite('Changing attribute bytes....', 6, 26, Attr);
  149.   Delay(1000);
  150.   Attr := Attribute(Back, Fore);
  151.  
  152.   {now some reverse video}
  153.   ChangeAttribute(2000, 1, 1, Attr);
  154.   for I := 10 to 20 do
  155.     FastWrite('IS PRETTY DARNED FAST NOW TOO!', I, 25, Attr);
  156.   Delay(1000);
  157.   FastWrite('But who says you need to....', 6, 26, Attr);
  158.   Delay(1000);
  159.  
  160.   {now write fast without messing with attributes}
  161.   for I := 10 to 20 do
  162.     FastWriteNA('MESS WITH THE ATTRIBUTE BYTES?', I, 25);
  163.   Delay(1000);
  164.  
  165.   {now restore the blinking version of the screen we saved}
  166.   MoveToScreen(ScreenBuffer, Mem[BaseOfScreen:0], 2000);
  167. end.
  168.